package win.larryzeal.logdemo.web.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import win.larryzeal.logdemo.pojo.User;
import win.larryzeal.logdemo.service.UserService;

@RestController
@RequestMapping( "/user" )
public class UserController {
	Logger logger = LoggerFactory.getLogger(UserController.class);

	@Autowired
	private UserService userService;


	@RequestMapping( value = "/{id}", method = RequestMethod.GET )
	public User get(@PathVariable Integer id){
		User user = userService.getUserById(id);
		logger.debug("已查找到对象", user);

		return user;
	}

	@RequestMapping( value = "/", method = RequestMethod.POST )
	public User saveUser(User user){
		userService.saveUser(user);
		return user;
	}

}
